//
//  XCMNavgationViewController.m
//  糗事百科
//
//  Created by 奚超明 on 16/6/8.
//  Copyright © 2016年 奚超明. All rights reserved.
//

#import "XCMNavgationViewController.h"

@interface XCMNavgationViewController ()

@end

@implementation XCMNavgationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

+ (void)initialize
{
    // 设置标题颜色
    UINavigationBar *bar = [UINavigationBar appearance];
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    attributes[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [bar setTitleTextAttributes:attributes];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) {
        // 设置左上角返回图标
        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        backBtn.xcm_size = CGSizeMake(30, 30);
        
        // 设置左对齐
        backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        // 设置内边距
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);
        
        [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
        
        //隐藏tabBar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:YES];
}

#pragma mark - 返回
- (void)backAction
{
    [self popViewControllerAnimated:YES];
}

@end
